package com.goddess.yeecolor.tools;

import android.content.Context;
import android.content.SharedPreferences;

import com.goddess.yeecolor.activity.MyAppClient;

/**
 * 用户偏好
 */
public class SharePreceUtils {
    private static SharedPreferences preferences;
    private static SharedPreferences.Editor editor=null;

    /**
     * 保存基本信息
     *   偏好名user
     */
    public static void saveData(String unique,String thumb,String nickname,String weixinid,String industry,String occupation,String city,String company,String mobile,boolean islogin,String id){
        preferences= MyAppClient.getInstance().getSharedPreferences("user", Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putString("unique",unique);
        editor.putString("thumb",thumb);
        editor.putString("nickname",nickname);
        editor.putString("weixinid",weixinid);
        editor.putString("industry",industry);
        editor.putString("occupation",occupation);
        editor.putString("company",company);
        editor.putString("city",city);
        editor.putString("mobile",mobile);
        editor.putBoolean("isLogin",islogin);
        editor.putString("id",id);
        editor.commit();
    }
    /**
     * 注册信息
     */
    public static void saveRegiter(String unique,int mobile){
        preferences= MyAppClient.getInstance().getSharedPreferences("righter", Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putString("unique",unique);
        editor.putInt("mobile",mobile);
        editor.commit();
    }
    /**
     * 设置单个Int类型
     */
    public static void saveOne(String name,Object value,String key){
        preferences= MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putInt(key, (int)value);
        editor.commit();
    }
    /**
     * 设置单个String类型
     */
    public static void saveString(String name,Object value,String key){
        preferences= MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putString(key, (String)value);
        editor.commit();
    }
    /**
     * 清除用户偏好
     * @param name
     */
    public static void clearData(String name){
        preferences= MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.clear();
        editor.commit();
    }

    /**
     * 获取其中一个String 类型
     */
    public static String getOther(String name,String tag){
        preferences= MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return preferences.getString(tag,"");
    }

    /**
     * 获取其中一个boolean 类型
     */
    public static boolean getBoolean(String name,String tag){
        preferences= MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return preferences.getBoolean(tag,false);
    }

    /**
     * 获取其中一个int 类型
     */
    public static int getInt(String name,String tag) {
        preferences = MyAppClient.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return preferences.getInt(tag, 0);
    }

    /**
     * 设置UUID 第三方登录
     */
    public static void saveLoginUUid(String uuid,String typed){
        preferences= MyAppClient.getInstance().getSharedPreferences("loginUuid", Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putString("userid",uuid);
        editor.putString("typed",typed);
        editor.commit();
    }

    /**
     * 保存订单
     */
    public static void saveOrder(String order_id,String title,String price){
        preferences= MyAppClient.getInstance().getSharedPreferences("order", Context.MODE_PRIVATE);
        editor=preferences.edit();
        editor.putString("order_id",order_id);
        editor.putString("title",title);
        editor.putString("price",price);
        editor.commit();
    }
}
